/*
 * Project: Sudoku Explainer
 * Copyright (C) 2006-2007 Nicolas Juillerat
 * 
 * Project: Sudoku Hint Engine for Android
 * Copyright (C) 2010-2013 Emanuel Moecklin
 * 
 * Available under the terms of the Lesser General Public License (LGPL)
 */
package com.onegravity.sudoku.solver.data;

import com.onegravity.sudoku.solver.HintResource;
import com.onegravity.sudoku.solver.R;
import com.onegravity.sudoku.solver.util.Settings;

/**
 * A column a sudoku grid
 */
public class Column extends Region {

	private static final long serialVersionUID = -2263748613609757523L;
	
	private int columnNum;
	private Grid grid;

    Column(Grid grid, int columnNum) {
    	this.grid = grid;
        this.columnNum = columnNum;
        initRegion();
    }

    public int getColumnNum() {
        return this.columnNum;
    }

    @Override
    public Cell getCell(int index) {
        return grid.getCell(columnNum, index);
    }

    @Override
    public int indexOf(Cell cell) {
    	int y = cell.getY();
    	return (getCell(y).equals(cell)) ? y : -1;
    }

    @Override
    public boolean crosses(Region other) {
    	return (other instanceof Block) ? ((Block)other).crosses(this) :
    		   (other instanceof Row) ? true :
    		   (other instanceof Column) ? (columnNum == ((Column)other).columnNum) :
               super.crosses(other);
    }

    @Override
    public String toString() {
    	return HintResource.getString(R.string.hint_region_column);
    }

    @Override
    public String toFullString() {
        if (Settings.isRCNotation())
            return toString() + " C" + (columnNum + 1); //$NON-NLS-1$
        else
            return toString() + " " + (char)('A' + columnNum); //$NON-NLS-1$
    }

    @Override
    public boolean equals(Object obj) {
    	if (! (obj instanceof Column)) return false;
    	return columnNum == ((Column) obj).columnNum;
    }

	@Override
	public int compareTo(Region another) {
		if (another instanceof Row) return 1;
		if (another instanceof Block) return -1;
		if (another instanceof ExtraRegionExtended) return -1;
    	return columnNum < ((Column) another).columnNum ? -1 : 1;
	}

}